home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / LDB171.ARJ / STRBDR.CPP < prev    next >
C/C++ Source or Header  |  1992-05-12  |  2KB  |  123 lines

  1. /*
  2.     StrBdr.cpp -- Loose Data Binder v 1.7:
  3.         container class "form."
  4.  
  5.     (C) Copyright 1992  John W. Small
  6.     All rights reserved
  7.  
  8.     PSW / Power SoftWare
  9.     P.O. Box 10072
  10.     McLean, Virginia 22102 8072 USA
  11.     (703) 759-3838
  12.  
  13.     See notes in fbinder.hpp!
  14. */
  15.  
  16.  
  17. #ifndef StrBdr_HPP
  18. #include "StrBdr.hpp"
  19. #endif
  20.  
  21. #include <string.h>
  22.  
  23.  
  24. int StrBdr::initData(/* StrBdr-declared data
  25.     member initializers */)
  26. {
  27.     // initialize any StrBdr-declared data
  28.     // members here
  29.     return 1;  // success
  30. }
  31.  
  32. voiD StrBdr::Dassign(voiD D, const voiD S)
  33. {
  34.     while (*(char *)D)
  35.         if ((*((char *)D)++ = *((char *)S)++ )
  36.             == '\0')  break;
  37.     return D;
  38. }
  39.  
  40. voiD StrBdr::Dnew(const voiD D)
  41. {
  42.     // invokes char's copy initializer constructor
  43.     return  (voiD) strdup((char *)D);
  44. }
  45.  
  46. void StrBdr::Ddelete(voiD D)
  47. {
  48.     // invokes char's destructor
  49.     delete (char *) D;
  50. }
  51.  
  52. void StrBdr::Dstore(ostream& os, voiD D)
  53. {
  54.     int i = strlen((char *)D);
  55.     
  56.     os << i << BDRendm;
  57.     if (i)
  58.         os.write((char *)D,i);
  59. }
  60.  
  61. voiD StrBdr::Dload(istream& is)
  62. {
  63.     char * D;
  64.     int i;
  65.  
  66.     is >> i >> BDRnextm;
  67.     if ((D = new char[i+i]) != (char *)0)  {
  68.         if (i)
  69.             is.read(D,i);
  70.         D[i] = '\0';
  71.     }
  72.     return (voiD) D;
  73. }
  74.  
  75. void StrBdr::store(ostream& os)
  76. {
  77.     Binder::store(os);
  78. //    os << StrBdr-declared data members << BDRendm;
  79. //    if (!os)
  80. //        berror("unable to store StrBdr "
  81. //            "data on stream");
  82. }
  83.  
  84.  
  85. StrBdR StrBdr::load(istream& is, StrBdR thiS)
  86. {
  87.     int newed;
  88.  
  89. //    is >> StrBdr-declared data member initializers
  90. //        >> BDRnextm;
  91. //    if (!is)  {
  92. //        sberror("unable to load StrBdr "
  93. //            "data from stream");
  94. //        return StrBdR0;
  95. //    }
  96.     if (thiS)
  97.         newed = 0;
  98.     else  {
  99.         if ((thiS = new StrBdr(initVFTsOnly))
  100.             == StrBdR0)  {
  101.             sberror("unable to construct "
  102.                 "new StrBdr for "
  103.                 "loading");
  104.             return StrBdR0;
  105.         }
  106.         newed = 1;
  107.     }
  108.     if (!Binder::load(is,(BindeR)thiS))  {
  109.         if (newed)
  110.             delete (voiD) thiS;
  111.         return StrBdR0;
  112.     }
  113.     if (!thiS->initData(/* StrBdr-declared data
  114.         member initializers */))  {
  115.         sberror("nunable to initialize StrBdr "
  116.             "from reloaded stream data");
  117.         if (newed)
  118.             delete (voiD) thiS;
  119.         return StrBdR0;
  120.     }
  121.     return thiS;
  122. }
  123.